/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 08 - 23
 * Time: 16:01
 */
//牛客 两个链表的第一个公共结点
public class Solution5 {
    public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
        ListNode p1 = pHead1, p2 = pHead2;
        while(p1 != p2) {
            p1 = p1 == null ? pHead2 : p1.next;
            p2 = p2 == null ? pHead1 : p2.next;
        }
        return p1;//包括p1或p2为null、p1和p2为null、p1p2指向同一个链表等情况
    }
}
